package creators;

import physicalobjects.Bar;
import physicalobjects.Mass;
import physicalobjects.Muscle;
import physicalobjects.Spring;
import simulationhandlers.Simulation;

/**
 * Creates springs.
 * @author Kathleen Lan, Seon Kang
 */

public class SpringCreator extends Creator {
    private String myCreatorName = "spring";
    /**
     * 
     * @param sim 
     * @param assemblyNumber 
     */
    public SpringCreator (Simulation sim, int assemblyNumber) {
        super(sim, assemblyNumber);
        setName(myCreatorName);
    }

    /**
     * @return
     */
    public Spring createMyObject () {
        int m1 = scannerNextInt();
        int m2 = scannerNextInt();
        double restLength = scannerNextDouble();
        double ks = scannerNextDouble();
        Mass start = getSimulation().getMass(m1, getAssemblyNumber());
        Mass end = getSimulation().getMass(m2, getAssemblyNumber());
        if (scannerHasNextDouble()) {
            double amplitude = scannerNextDouble();
            return new Muscle(start, end, restLength, ks,
                    amplitude);
        }
        if (ks < 0) {
            return new Bar(start, end, restLength, ks);
        }
        return new Spring(start, end, restLength, ks);
    }
}
